package org.fixed.dubboconsumer.core.util;

import org.appformer.maven.integration.ArtifactResolver;
import org.appformer.maven.integration.embedder.MavenSettings;
import org.appformer.maven.support.AFReleaseId;
import org.appformer.maven.support.AFReleaseIdImpl;
import org.eclipse.aether.artifact.Artifact;

import java.io.File;

/**
 * @author [xuzhongwei]
 * @see [相关类/方法]
 * @since 2020/1/18
 */
public class MavenRepository {

    private final static String DEFALUT_MAWEN_HOME = "MAVEN_HOME";

    static {
        System.setProperty(MavenSettings.CUSTOM_SETTINGS_PROPERTY, System.getenv(DEFALUT_MAWEN_HOME) + File.separator + "conf" + File.separator + "settings.xml");
    }
    /**
     * 下载依赖jar
     *
     * @param groupId
     * @param artifactId
     * @param version
     */
    public static File loadWithDependency(String groupId, String artifactId, String version) {
        ArtifactResolver artifactResolver = new ArtifactResolver();
        AFReleaseId afReleaseId = new AFReleaseIdImpl(groupId, artifactId, version);
        Artifact artifact = artifactResolver.resolveArtifact(afReleaseId);
        return artifact.getFile();
    }
}
